﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LabMS.Web.Parameters
{
    public partial class GradeConversion : Base.BasePage
    {
        LabMS.BLL.ScoreConversion BSC = new LabMS.BLL.ScoreConversion();
        protected void Page_Load(object sender, EventArgs e)
        {
            strPagePrivilege.Add("CJZHBZDZB");
            strPageUserType.Add("mana");
            if (!IsPostBack)
            {
                InitBind();
            }
        }

        /// <summary>
        /// 初始化页面
        /// </summary>
        protected void InitBind()
        {
            DataSet ds = new DataSet();
            ds=BSC.GetAllList();
            for (int i = 1; i <= 5; i++)
            {
                HtmlInputText inputText =(HtmlInputText)this.FindControl("t"+i.ToString());//t1
                HtmlInputText inputText2 = (HtmlInputText)this.FindControl("t" + i.ToString() + i.ToString());//t11
                HtmlInputText inputText3 = (HtmlInputText)this.FindControl("tb" + i.ToString());//tb1
                inputText.Value = ds.Tables[0].Rows[i-1]["Percentile"].ToString();
                inputText2.Value=ds.Tables[0].Rows[i-1]["Percentile2"].ToString();
                inputText3.Value = ds.Tables[0].Rows[i - 1]["Level"].ToString();
            }
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            #region 验证
            bool a = false;
            for (int i = 1; i <= 5; i++)
            {
                HtmlInputText tb =(HtmlInputText)this.FindControl("tb" + i.ToString());
                HtmlInputText t = (HtmlInputText)this.FindControl("t"+i.ToString());
                HtmlInputText tt = (HtmlInputText)this.FindControl("t"+i.ToString()+i.ToString());
                if (!string.IsNullOrEmpty(tb.Value)&&!string.IsNullOrEmpty(t.Value)&&!string.IsNullOrEmpty(tt.Value))
                {
                    a = true;
                }
                else
                {
                    a = false;
                    break;
                }
            }
            if (!a)
            {
                Common.JShelper.JSAlert(this.Page, "", "请填写完整！");
            }
            #endregion
            else
            {
                LabMS.Model.ScoreConversion MSC = new LabMS.Model.ScoreConversion();
                for (int i = 1; i <= 5; i++)
                {
                    HtmlInputText inputText = (HtmlInputText)this.FindControl("t" + i.ToString());//t1
                    HtmlInputText inputText2 = (HtmlInputText)this.FindControl("t" + i.ToString() + i.ToString());//t11
                    HtmlInputText inputText3 = (HtmlInputText)this.FindControl("tb" + i.ToString());//tb1
                    MSC.ID = i;
                    if (!string.IsNullOrEmpty(inputText.Value)&&!string.IsNullOrEmpty(inputText2.Value))
                    {
                        MSC.Percentile = decimal.Parse(inputText.Value);
                        MSC.Percentile2 = decimal.Parse(inputText2.Value);
                        MSC.Level = inputText3.Value;
                        BSC.Update(MSC);
                    }
                }
                Common.JShelper.JSAlert(this.Page, "", "保存成功！");
            }
        }
    }
}
